﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using OnlineSoccerManager.Helper;

namespace OnlineSoccerManager.Classes
{
    public class CommonSkills
    {
        private Dictionary<string, decimal> commonSkills = new Dictionary<string, decimal>();
        private Dictionary<string, decimal> commonChanges = new Dictionary<string, decimal>();
        private List<SkillChange> changeSummary;


        public decimal? Endurance
        {
            get
            {
                if (this.commonSkills.ContainsKey("Endurance"))
                    return this.commonSkills["Endurance"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.commonSkills["Endurance"] = value.Value;
            }
        }
        public decimal? Morale
        {
            get
            {
                if (this.commonSkills.ContainsKey("Morale"))
                    return this.commonSkills["Morale"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.commonSkills["Morale"] = value.Value;
            }
        }
        public decimal? Fitness
        {
            get
            {
                if (this.commonSkills.ContainsKey("Fitness"))
                    return this.commonSkills["Fitness"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.commonSkills["Fitness"] = value.Value;
            }
        }


        public decimal? FitnessChange
        {
            get
            {
                if (this.commonChanges.ContainsKey("FitnessChange"))
                    return this.commonChanges["FitnessChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.commonChanges["FitnessChange"] = value.Value;
            }
        }

        public decimal? EnduranceChange
        {
            get
            {
                if (this.commonChanges.ContainsKey("EnduranceChange"))
                    return this.commonChanges["EnduranceChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.commonChanges["EnduranceChange"] = value.Value;
            }
        }
        public decimal? MoraleChange
        {
            get
            {
                if (this.commonChanges.ContainsKey("MoraleChange"))
                    return this.commonChanges["MoraleChange"];

                return null;
            }
            set
            {
                if (value == null || !value.HasValue)
                    return;
                this.commonChanges["MoraleChange"] = value.Value;
            }
        }


        public IEnumerable<SkillChange> ChangeSummary
        {
            get
            {
                if (this.changeSummary != null)
                    return this.changeSummary;

                this.changeSummary = new List<SkillChange>();
                foreach (var entry in this.commonChanges.Where(e => e.Value != 0))
                    this.changeSummary.Add(new SkillChange() { Icon = (entry.Value > 0 ? this.ChangeUpImage : this.ChangeDownImage), Name = entry.Key, Value = entry.Value });

                return this.changeSummary;
            }
        }

        public ImageSource ChangeUpSource { get { return this.ChangeUpImage.GetImageSource(); } }
        public Bitmap ChangeUpImage { get; set; }
        public ImageSource ChangeDownSource { get { return this.ChangeDownImage.GetImageSource(); } }
        public Bitmap ChangeDownImage { get; set; }
    }
}
